import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import { viteMockServe } from 'vite-plugin-mock'
import path from 'path'

export default defineConfig({
    plugins: [
        vue(),
        createSvgIconsPlugin({
            iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
            symbolId: 'icon-[dir]-[name]',
            inject: 'body-last',
            customDomId: '__SVG_ICON_SPRITE__',
        }),
        AutoImport({
            // 自动引入 Vue 相关 API
            imports: ['vue', 'vue-router'],
            dts: true, // 确保路径正确
            // 自动引入 Element Plus 相关 API
            resolvers: [ElementPlusResolver({})],
        }),
        Components({
            resolvers: [ElementPlusResolver()],
            dts: true, // 生成类型声明文件
        }),
        viteMockServe({
            mockPath: 'mock',
            enable: true,
            logger: true, // 是否在控制台显示请求日志
        }),
    ],
    resolve: {
        alias: {
            '@': path.resolve(__dirname, 'src'), // 将 @ 指向 src 目录
        },
    },
    css: {
        preprocessorOptions: {
            scss: {
                additionalData: '@use "@/styles/variable.scss";',
            },
        },
    },
})
